# coding: utf-8

# http://wiki.it.yzs.io:8090/pages/viewpage.action?pageId=38915151

from utils.req import *
from utils.jktest import *


######################################################
#           开发者网站技能调用                        #
######################################################

def get_lastest_skill():
    '''已上架状态的最新版本技能'''
    url = "http://%s/%s/skill/get_lastest_skill" % (Server, Project)
    params = {
        "skillOrigin" : Origin,
        "appKey": AppKey,
        "userId": UserId
    }

    send_get(url, params)

def get_my_skill():
    '''已上架状态的最新版本技能'''
    url = "http://%s/%s/skill/get_my_skill" % (Server, Project)
    params = {
        "appKey": AppKey,
        "userId": UserId,
        "keyword": "",
    }

    send_get(url, params)

def list_version():
    '''分页查询单个技能多版本列表'''
    url = "http://%s/%s/skill/list_version" % (Server, Project)
    params = {
        "skillOrigin" : Origin,
        "skillId": SkillId,
    }

    send_get(url, params)

def get_latest_version():
    '''技能最新版本'''
    url = "http://%s/%s/skill/get_lastest_version" % (Server, Project)
    params = {
        "appKey": AppKey,
        "userId": UserId,
        "skills":[ 
            {
            "skillId": SkillId,
            "skillOrigin" : Origin,
            },
        ]
    }

    send_post(url, params, jsondump=True)




######################################################
#           技能授权API定义                           #
######################################################


def authority_list():
    '''查询技能授权情况列表'''
    url = "http://%s/%s/skill/authority/list" % (Server, Project)
    params = {
        "userName" : UserName,
        "appkey": AppKey,
        "pageNum":1,
        "pageSize":10
    }

    send_get(url, params)

def authority_detail_list():
    ''' 查询技能授权列表详情 '''
    url = "http://%s/%s/skill/authority/detail/list" % (Server, Project)
    params = {
        "authorityId": AuthorityId,
        "userId" : UserId,
        "appkey": AppKey,
    }

    send_get(url, params)

def authority_detail_add():
    url = "http://%s/%s/skill/authority/detail/add" % (Server, Project)
    params = {
        "authorityType" : "user", # user,appkey,udid
        "grantUserName": "",
        "grantUserId": "",
        "beginDate": "",
        "endDate": "",
        "skillName": "",
        "skillId": "",
        "userNameAbbr": "", # 客户简称
        "userName": "", # 客户名称
        "userId": "",
        "productName": "",
        "appkey": AppKey
    }

    send_get(url, params)

def authority_detail_update():
    url = "http://%s/%s/skill/authority/detail/update" % (Server, Project)
    params = {
        "skillAuthorityDetailId" : "", # 技能授权详情id
        "beginDate": "",
        "endDate": "",
        "grantUserName": "",
        "grantUserId": "",
    }

    send_get(url, params)

def authority_detail_delete():
    url = "http://%s/%s/skill/authority/detail/delete" % (Server, Project)
    params = {
        "skillAuthorityDetailId" : "", # 技能授权详情id
    }

    send_get(url, params)

def authority_delete():    
    url = "http://%s/%s/skill/authority/delete" % (Server, Project)
    params = {
        "skillAuthorityId" : "", # 技能授权详情id
    }

    send_get(url, params)


def authority_can_authorized():
    ''' 查询可授权的技能列表 '''
    url = "http://%s/%s/skill/authority/can_authorized" % (Server, Project)
    params = {
        "skillName" : "", # 技能名称
        "appkey": AppKey,
        "userId": UserId,
        "pageNum": 1,
        "pageSize": 10,
    }

    send_get(url, params)




#########################################
#           技能列表API定义              #
#########################################

def skill_list():
    ''' 查询是最终技能版本的技能版本列表 '''
    url = "http://%s/%s/skillVesion/skill_list" % (Server, Project)
    params = {
        "skillSource" : "1", # 1：云知声 2：合作方 3：普通开发者
        "skillName": "",
        "userName": UserName,
        "pageNum": 1,
        "pageSize": 10,
    }

    send_get(url, params)

def update_shop_status():
    '''修改技能商城状态'''
    url = "http://%s/%s/master_skill/update_shop_status" % (Server, Project)
    params = {
        "skillId" : SkillId,
        "shopStatus" : 0 # 0：未上架 1：上架公开 2：上架未公开 
    }

    send_get(url, params)

def version_list():
    url = "http://%s/%s/skillVesion/version_list" % (Server, Project)
    params = {
        "skillId" : SkillId,
        "skillSource" : "3", # 1：云知声 2：合作方 3：普通开发者
        "skillName": "",
        "userName": UserName,
        "pageNum": 1,
        "pageSize": 10,
    }

    send_get(url, params)


def version_update():
    url = "http://%s/%s/skillVesion/update" % (Server, Project)
    params = {
    # 1：审核中 2：审核未通过 3：审核通过 10：自发布  11：已上架 12：已下架  13:已上架不公开
        "status" : 12,
        "skillVersionId": "1508" # skill_version 表的id主键
    }

    send_get(url, params)


def version_authorized():
    url = "http://%s/%s/skillVesion/authorized" % (Server, Project)
    params = {
        "skillId" : SkillId,
        "authorityType": "user", # 授权类型(user,appkey,udid)
        "pageNum": 1,
        "pageSize": 10,
    }

    send_get(url, params)




#########################################
#           技能类型统计API              #
#########################################
def statistic_type_count():
    url = "http://%s/%s/skill/statistic/type_count" % (Server, Project)
    params = {
        "typeId":1
    }

    send_get(url, params)

def statistic_category_count():
    url = "http://%s/%s/skill/statistic/category_count" % (Server, Project)
    params = {
        "categoryId":2
    }

    send_get(url, params)




#########################################
#        支持开发者网站等接口            #
#########################################

def get_my_master_skill():
    ''' 获取我的技能 '''
    url = "http://%s/%s/master_skill/get_my_skill" % (Server, Project)
    params = {
        "userId" : UserId,
    }
    send_get(url, params)

def get_batch_skill_version():
    ''' 根据技能ID和技能版本批量查询技能版本信息（/skillVesion/batch_skill_version）'''
    url = "http://%s/%s/skillVesion/batch_skill_version" % (Server, Project)

    params = {
        "skillIds" : SkillId,
        "skillVersions" : "",
    }
    send_get(url, params)




if __name__ == '__main__':
    AppKey = "vihbue6kvclagieoslsrnvdrprqtj6adqmxcvmai" # 自动化测试关联
    Server = "172.18.10.81:8080" # UAT
    Project = "unios-usk-manager/rest/v1"
    SkillId = "2e09f5b99d26424b8e5bb5561bbc9342" # 自动化测试
    SkillVersion = '1.0.19'

    Origin = 2 # 技能来源（1：官方技能，2：第三方技能)
    UserId = 4093
    UserName = "dakangz"
    AuthorityId = ''

    # 开发者网站调用
    # get_lastest_skill()
    # get_my_skill()
    # list_version()
    # get_latest_version() ####################

    # 技能授权API
    # authority_list()
    # authority_detail_list()
    # authority_detail_add()
    # authority_detail_update()
    # authority_detail_delete()
    # authority_delete()
    # authority_can_authorized()

    # 技能列表API
    # skill_list()
    # update_shop_status()
    # version_list()
    version_update() ####################
    # version_authorized()

    # 技能类型统计API
    # statistic_type_count()
    # statistic_category_count()

    # 开发者网站等接口
    # get_my_master_skill()
    # get_batch_skill_version()